<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{
    protected $table = 'goods';

    protected $fillable = [
		'goods_name','category_id','thumb','brand_id','price','sort','status','description','type_id','inventory','kill_status'
	];

	/**
	 * 一对多关联商品属性 一个商品有多个属性
	 * User: Clannad ~ ☆
	 * DataTime：2019/11/16 0016 15:45
	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
	 */
	public function goods_spec()
    {
		return $this->hasMany(GoodsSpec::class,'goods_id','id');
    }

	/**
	 * 一对多关联sku
	 * User: Clannad ~ ☆
	 * DataTime：2019/11/17 0017 15:27
	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
	 */
	public function goods_sku()
    {
		return $this->hasMany(GoodsSku::class,'goods_id','id');
    }

    //关联分类
	public function category()
    {
		return $this->hasOne(GoodsCategory::class,'id','category_id');
    }

    //关联品牌
	public function brand()
	{
		return $this->hasOne(GoodsBrand::class,'id','brand_id');
	}

	/**
	 * 商品相册
	 * User: Clannad ~ ☆
	 * DataTime：2019/11/18 0018 11:40
	 */
	public function goods_album()
	{
		return $this->hasMany(GoodsAlbum::class,'goods_id','id');
	}

    /**
     * 与秒杀的1对1关联
     * User: Clannad ~ ☆
     * DataTime：2020/7/14 0014 17:23
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function seckill_goods()
	{
        return $this->hasOne(SeckillGoods::class,'goods_id','id');
	}
}
